package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.common.result.Result;
import com.atguigu.srb.core.pojo.entity.UserInfo;
import com.atguigu.srb.core.pojo.entity.vo.UserInfoSearchVo;
import com.atguigu.srb.core.service.UserInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 用户基本信息 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2023-03-25
 */
@RestController
@RequestMapping("/admin/core/userInfo")
//@CrossOrigin
@Api("会员管理")
public class AdminUserInfoController {
    @Resource
    UserInfoService userInfoService;

    @ApiOperation("会员分页列表")
    @GetMapping("/userList/{pageNum}/{pageSize}")
    public Result getUserList(
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize,
            UserInfoSearchVo userInfoSearchVo
    ){
        Page<UserInfo> page = userInfoService.getUserList(pageNum, pageSize, userInfoSearchVo);
        return Result.ok().data("page", page);
    }

    @ApiOperation("锁定和解锁")
    @PutMapping("/updateStatus/{userId}/{status}")
    public Result updateStatus(
            @PathVariable("userId") String userId,
            @PathVariable("status") Integer status
    ){
        userInfoService.updateStatus(userId, status);
        return Result.ok().message(0==status ? "锁定成功" : "解锁成功");
    }
}